package com.lrkj.workorder.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.domain.entity.RepairFeeScale;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.workorder.service.IRepairFeeScaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报修收费标准Controller
 *
 * @author yajun_ren
 * @date 2022-04-22
 */
@RestController
@RequestMapping("/workorder/repairFeeScale")
@Api(tags = "报修收费标准")
public class RepairFeeScaleController extends BaseController {
    @Autowired
    private IRepairFeeScaleService repairFeeScaleService;

    /**
     * 查询报修收费标准列表
     */
    @ApiOperation(value = "查询报修收费标准列表", notes = "查询报修收费标准列表")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairFeeScale repairFeeScale) {
        startPage();
        this.changeParameter(repairFeeScale.getParams());
        List<RepairFeeScale> list = repairFeeScaleService.selectRepairFeeScaleList(repairFeeScale);
        return getDataTable(list);
    }

    /**
     * 导出报修收费标准列表
     */
    @ApiOperation(value = "导出报修收费标准列表", notes = "导出报修收费标准列表")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:export')")
    @Log(title = "报修收费标准", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RepairFeeScale repairFeeScale) {
        List<RepairFeeScale> list = repairFeeScaleService.selectRepairFeeScaleList(repairFeeScale);
        ExcelUtil<RepairFeeScale> util = new ExcelUtil<RepairFeeScale>(RepairFeeScale.class);
        return util.exportExcel(list, "报修收费标准数据");
    }

    /**
     * 获取报修收费标准详细信息
     */
    @ApiOperation(value = "获取报修收费标准详细信息", notes = "获取报修收费标准详细信息")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(repairFeeScaleService.selectRepairFeeScaleById(id));
    }

    /**
     * 新增报修收费标准
     */
    @ApiOperation(value = "新增报修收费标准", notes = "新增报修收费标准")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:add')")
    @Log(title = "报修收费标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairFeeScale repairFeeScale) {
        return toAjax(repairFeeScaleService.insertRepairFeeScale(repairFeeScale));
    }

    /**
     * 修改报修收费标准
     */
    @ApiOperation(value = "修改报修收费标准", notes = "修改报修收费标准")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:edit')")
    @Log(title = "报修收费标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairFeeScale repairFeeScale) {
        return toAjax(repairFeeScaleService.updateRepairFeeScale(repairFeeScale));
    }

    /**
     * 删除报修收费标准
     */
    @ApiOperation(value = "删除报修收费标准", notes = "删除报修收费标准")
    @PreAuthorize("@ss.hasPermi('workorder:repairFeeScale:remove')")
    @Log(title = "报修收费标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(repairFeeScaleService.deleteRepairFeeScaleByIds(ids));
    }
}
